package com.bao.work;

/**
 * @author baoye
 * @date 2024-07-23/18:44
 */
public class Exception01 {
    public static void main(String[] args) {
        /*Person person=new Person("超级狗大王",-1);*/
        Person person2=new Person();
        person2.setLifeValue(3);
        person2.setLifeValue(-5);
    }
}
class NoLifeValueException extends RuntimeException{

    public NoLifeValueException(String message) {
        super(message);
    }

    public NoLifeValueException() {
    }

}
class Person{
    private String name;
    private int lifeValue;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLifeValue() {
        return lifeValue;
    }

    public void setLifeValue(int lifeValue) {
        if(lifeValue<0){
            throw new NoLifeValueException("生命值不能为负数:"+lifeValue);
        }
        this.lifeValue = lifeValue;
    }

    public Person(String name, int lifeValue) {
        setName(name);
        setLifeValue(lifeValue);
    }

    public Person() {
    }
}
